#ifndef __DELAY_H__
#define __DELAY_H__
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <assert.h>

#define RX_NSEC_PER_USEC    1000ull         /* nanoseconds per microsecond */
#define RX_USEC_PER_SEC     1000000ull      /* microseconds per second */
#define RX_NSEC_PER_SEC     1000000000ull   /* nanoseconds per second */
#define RX_NSEC_PER_MSEC    1000000ull      /* nanoseconds per millisecond */
#define RX_MSEC_PER_SEC     1000ull         /* millisecond per second */
#define RX_USEC_PER_MSEC    1000ull         /* microseconds per millisecond */
#define RX_USEC_PER_MINUTE  60000000ull     /* microseconds per minute */

/* use this macro to eliminate the un-referenced variable */
#define RX_UNUSED(x) (void)x

uint64_t
rx_get_timestamp()
{
  struct timespec tp;
  int r = clock_gettime(CLOCK_MONOTONIC, &tp);
  assert(r == 0);
  RX_UNUSED(r);
  return (uint64_t)(tp.tv_sec * RX_USEC_PER_SEC + tp.tv_nsec / RX_NSEC_PER_USEC);
}
#endif  // __DELAY_H__